package com.vdong.interactive.course.web.controller;

import com.github.pagehelper.PageInfo;
import com.vdong.interactive.course.common.enums.ApiContract;
import com.vdong.interactive.course.common.supper.SupperController;
import com.vdong.interactive.course.entity.dto.*;
import com.vdong.interactive.course.entity.po.*;
import com.vdong.interactive.course.service.CourseCategoryService;
import com.vdong.interactive.course.service.PeddleGoodsService;
import io.swagger.annotations.*;
import org.lamb.framework.common.userDTO.AccountSystemUserInfoDTO;
//import org.lamb.framework.core.security.LambPrincipalFactoryContainer;
import org.lamb.framework.core.security.LambPrincipalFactoryContainer;
import org.lamb.framework.core.templete.LambResponseTemplete;
import org.springframework.beans.BeanUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 分销商品
 */
@Api(description = "分销商品",tags = "分销商品")
@RestController
@RequestMapping("/goods/peddleGoods")
public class PeddleGoodsController extends SupperController {

    @Resource
    private PeddleGoodsService peddleGoodsService;

    @Resource
    private CourseCategoryService courseCategoryService;

    @ApiOperation(value = "分销商品列表（Saas）" ,  notes="分销商品列表（Saas）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "checkState", value = "审核状态【0：待审核 1：通过 2：未通过 3:违规】", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "openState", value = "上架状态【1：上架 0：下架】", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "classifyType", value = "分类类型【0：课程】", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "keyword", value = "关键字", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isShow", value = "是否首页展示【0：不展示 1：展示】", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "条数", paramType = "query", dataType = "int"),
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功",response = LambResponseTemplete.class)
    })
    @RequestMapping(value= ApiContract.getPeddleGoodsList,method = RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
    public Mono<LambResponseTemplete> getPeddleGoodsList(@RequestBody GoodsPeddlePagePO po){
        AccountSystemUserInfoDTO systemUserInfoDTO = LambPrincipalFactoryContainer.getAccountSystemUser();
        if (!Objects.isNull(po.getKeyword())){
            po.setKeyword("%"+po.getKeyword()+"%");
        }
        PageInfo<GoodsPeddleListDTO> pageInfo = peddleGoodsService.getPeddleGoodsList(po.getCheckState()
                ,po.getOpenState()
                ,po.getClassifyType()
                ,po.getKeyword()
                ,null
                ,po.getIsShow()
                ,null
                ,po.getPage()
                ,po.getPageSize());
        return returning(pageInfo);
    }

    @ApiOperation(value = "首页推荐商品目录内容（Saas）" ,  notes="首页推荐商品目录内容（Saas）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "关键字", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "条数", paramType = "query", dataType = "int"),
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功",response = LambResponseTemplete.class)
    })
    @RequestMapping(value= ApiContract.indexGoodsChoice,method = RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
    public Mono<LambResponseTemplete> indexGoodsChoice(@RequestBody GoodsPeddlePagePO po){
        if (!Objects.isNull(po.getKeyword())){
            po.setKeyword("%"+po.getKeyword()+"%");
        }
        PageInfo<GoodsPeddleListDTO> pageInfo = peddleGoodsService.getIndexGoodsChoice(po.getKeyword(),null,po.getPage(),po.getPageSize());
        return returning(pageInfo);
    }

    @ApiOperation(value = "轮播图商品目录内容（Saas）" ,  notes="轮播图商品目录内容（Saas）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "关键字", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "条数", paramType = "query", dataType = "int"),
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功",response = LambResponseTemplete.class)
    })
    @RequestMapping(value= ApiContract.rotationGoodsChoice,method = RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
    public Mono<LambResponseTemplete> rotationGoodsChoice(@RequestBody GoodsPeddlePagePO po){
        if (!Objects.isNull(po.getKeyword())){
            po.setKeyword("%"+po.getKeyword()+"%");
        }
        PageInfo<GoodsPeddleListDTO> pageInfo = peddleGoodsService.rotationGoodsChoice(po.getKeyword(),null,po.getPage(),po.getPageSize());
        return returning(pageInfo);
    }

    @ApiOperation(value = "分销商品列表（商户）" ,  notes="分销商品列表（商户）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "checkState", value = "审核状态【0：待审核 1：通过 2：未通过 3:违规】", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "openState", value = "上架状态【1：上架 0：下架】", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "classifyType", value = "分类类型【0：课程】", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "keyword", value = "关键字", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isShow", value = "是否首页展示【0：不展示 1：展示】", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "条数", paramType = "query", dataType = "int"),
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功",response = LambResponseTemplete.class)
    })
    @RequestMapping(value= ApiContract.getStorePeddleGoodsList,method = RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
    public Mono<LambResponseTemplete> getStorePeddleGoodsList(@RequestBody GoodsPeddlePagePO po){
        AccountSystemUserInfoDTO systemUser = LambPrincipalFactoryContainer.getAccountSystemUser();
        if (!Objects.isNull(po.getKeyword())){
            po.setKeyword("%"+po.getKeyword()+"%");
        }
//
//        if (po.getCheckState().compareTo(1) == 0){
//            po.setCheckState(5);
//        }
        PageInfo<GoodsPeddleListDTO> pageInfo = peddleGoodsService.getStorePeddleGoodsList(po.getCheckState()
                ,po.getOpenState()
                ,po.getClassifyType()
                ,po.getKeyword()
                ,Long.parseLong(systemUser.getSysUserId())
                ,po.getIsShow()
                ,null
                ,po.getPage()
                ,po.getPageSize());
        return returning(pageInfo);
    }

    @ApiOperation(value = "获取分销商品详情（商户）" ,  notes="获取分销商品详情（商户）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "peddleGoodsId", value = "分销商品id", paramType = "query", dataType = "int"),
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功",response = LambResponseTemplete.class)
    })
    @RequestMapping(value= ApiContract.getStroePeddleGoodsDetail,method = RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
    public Mono<LambResponseTemplete> getStroePeddleGoodsDetail(@RequestBody PeddleGoodsOperationPO po){
        PeddleGoodsDetailDTO peddleGoodsDetailDTO = peddleGoodsService.getPeddleGoodsDetail(po.getPeddleGoodsId());
        return returning(peddleGoodsDetailDTO);
    }

    @ApiOperation(value = "获取分销商品详情（Saas）" ,  notes="获取分销商品详情（Saas）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "peddleGoodsId", value = "分销商品id", paramType = "query", dataType = "int"),
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功",response = LambResponseTemplete.class)
    })
    @RequestMapping(value= ApiContract.getPeddleGoodsDetail,method = RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
    public Mono<LambResponseTemplete> getPeddleGoodsDetail(@RequestBody PeddleGoodsOperationPO po){
        PeddleGoodsDetailDTO peddleGoodsDetailDTO = peddleGoodsService.getPeddleGoodsDetail(po.getPeddleGoodsId());
        return returning(peddleGoodsDetailDTO);
    }

    @ApiOperation(value = "目录内容（Saas）" ,  notes="目录内容（Saas）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "peddleGoodsId", value = "分销商品id", paramType = "query", dataType = "int"),
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功",response = LambResponseTemplete.class)
    })
    @RequestMapping(value= ApiContract.getGoodsSub,method = RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
    public Mono<LambResponseTemplete> getGoodsSub(@RequestBody GoodsPeddlePagePO po){
        return returning( peddleGoodsService.pageCourseSub(po.getPeddleGoodsId(),po.getPage(),po.getPageSize()));
    }

    @ApiOperation(value = "目录内容富文本（Saas）" ,  notes="目录内容富文本（Saas）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "subId", value = "分销商品id", paramType = "query", dataType = "int"),
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功",response = LambResponseTemplete.class)
    })
    @RequestMapping(value= ApiContract.getSubContext,method = RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
    public Mono<LambResponseTemplete> getSubContext(@RequestBody CourseSubPO po){
        return returning( peddleGoodsService.getSubContext(po.getSubId()));
    }

    @ApiOperation(value = "目录内容详情（Saas）" ,  notes="目录内容详情（Saas）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "subId", value = "分销商品id", paramType = "query", dataType = "int"),
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功",response = LambResponseTemplete.class)
    })
    @RequestMapping(value= ApiContract.getSubDetail,method = RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
    public Mono<LambResponseTemplete> getSubDetail(@RequestBody CourseSubPO po){
        return returning( peddleGoodsService.getCourseSubDetail(po.getSubId()));
    }

    @ApiOperation(value = "获取课程分类列表（Saas）" ,  notes="获取课程分类列表（Saas）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", value = "分类父id", paramType = "query", dataType = "int"),
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功",response = LambResponseTemplete.class)
    })
    @RequestMapping(value= ApiContract.getPeddleGoodsCategoryList,method = RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
    public Mono<LambResponseTemplete> getPeddleGoodsCategoryList(@RequestBody CourseCategoryPO po){
        List<CourseCategoryDTO> categoryList = courseCategoryService.getCourseCategoryList(po.getParentId());
        return returning(categoryList);
    }

    @ApiOperation(value = "获取课程分类列表（商户）" ,  notes="获取课程分类列表（商户）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", value = "分类父id", paramType = "query", dataType = "int"),
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功",response = LambResponseTemplete.class)
    })
    @RequestMapping(value= ApiContract.getStorePeddleGoodsCategoryList,method = RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
    public Mono<LambResponseTemplete> getStorePeddleGoodsCategoryList(@RequestBody CourseCategoryPO po){
        List<CourseCategoryDTO> categoryList = courseCategoryService.getCourseCategoryList(po.getParentId());
        return returning(categoryList);
    }

    @ApiOperation(value = "分销商品列表（用户端,全部课程）" ,  notes="分销商品列表（用户端,全部课程）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "classifyType", value = "分类类型【0：课程】", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "keyword", value = "关键字", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isShow", value = "是否首页展示【0：不展示 1：展示】", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "条数", paramType = "query", dataType = "int"),
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功",response = LambResponseTemplete.class)
    })
    @RequestMapping(value= ApiContract.getAppPeddleGoodsList,method = RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
    public Mono<LambResponseTemplete> getAppPeddleGoodsList(@RequestBody AppPeddleGoodsPagePO po){
        if (!Objects.isNull(po.getKeyword())){
            po.setKeyword("%"+po.getKeyword()+"%");
        }
        PageInfo<AppPeddleGoodsDTO> pageInfo = peddleGoodsService.getAppPeddleGoodsPage(po.getKeyword()
                ,po.getCategoryId()
                ,po.getTypeId()
                ,po.getClassifyType()
                ,po.getSort()
                ,po.getIsShow()
                ,po.getPage()
                ,po.getPageSize());
        return returning(pageInfo);
    }

    @ApiOperation(value = "首页推荐（用户端）" ,  notes="首页推荐（用户端）")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功",response = LambResponseTemplete.class)
    })
    @RequestMapping(value= ApiContract.getAppIndexPeddleGoodsList,method = RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
    public Mono<LambResponseTemplete> getAppIndexPeddleGoodsList(@RequestBody AppPeddleGoodsPagePO po){
        if (!Objects.isNull(po.getKeyword())){
            po.setKeyword("%"+po.getKeyword()+"%");
        }
        PageInfo<AppPeddleGoodsDTO> pageInfo = peddleGoodsService.getAppPeddleGoodsPage(po.getKeyword()
                ,po.getCategoryId()
                ,po.getTypeId()
                ,po.getClassifyType()
                ,po.getSort()
                ,1
                ,po.getPage()
                ,po.getPageSize());
        return returning(pageInfo);
    }

    @ApiOperation(value = "获取课程分类列表（用户端）" ,  notes="获取课程分类列表（用户端）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", value = "分类父id", paramType = "query", dataType = "int"),
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功",response = LambResponseTemplete.class)
    })
    @RequestMapping(value= ApiContract.getAppPeddleGoodsCategoryList,method = RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
    public Mono<LambResponseTemplete> getAppPeddleGoodsCategoryList(@RequestBody CourseCategoryPO po){
        List<CourseCategoryDTO> categoryList = courseCategoryService.getCourseCategoryList(po.getParentId());
        return returning(categoryList);
    }

    @ApiOperation(value = "获取分销商品详情（用户端）" ,  notes="获取分销商品详情（用户端）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "peddleGoodsId", value = "分销商品id", paramType = "query", dataType = "int"),
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功",response = LambResponseTemplete.class)
    })
    @RequestMapping(value= ApiContract.getAppPeddleGoodsDetail,method = RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
    public Mono<LambResponseTemplete> getAppPeddleGoodsDetail(@RequestBody PeddleGoodsOperationPO po){
        AppPeddleGoodsDetailDTO goodsDetail = peddleGoodsService.getAppPeddleGoodsDetail(po.getPeddleGoodsId());
        return returning(goodsDetail);
    }
}
